package com.ybkj.o2o.mc.common;

import org.apache.commons.lang.StringUtils;

import java.util.regex.Pattern;

public class PhoneNumberHelper {

  /**
   * 判断是否为手机号码.
   *
   * @param input 输入字符串
   * @return true是手机号码, false不是手机号码
   */
  public static boolean isPhoneNumber(String input) {
    String regex = "^[0-9]{1,15}$";
    //String regex = "(^(13[0-9]|14[0-9]|15[0-9]|17[0-9]|18[0-9])\\d{8})|
    // ((400)-(\\d{3})-(\\d{4}))|((4000)-(\\d{3})-(\\d{3}))|((400)-(\\d{4})-
    // (\\d{3}))|((400)\\d{7})|(\\d{7,8})|((0)(\\d{7,10}))|((\\d{3})-(\\d{7,8}))
    // |((\\d{3,4})-(\\d{7,8})-(\\d{1,2}))$";

    return Pattern.matches(regex, input);
  }

  /**
   * 判断是否为座机号码.
   *
   * @param input 输入字符串
   * @return true是座机号码, false不是座机号码
   */
  public static boolean isTelephoneNumber(String input) {
    String regex = "^[0-9]{3,5}-[0-9]{7,8}$";

    return Pattern.matches(regex, input);
  }

  /**
   * 判断是否为手机或者座机号码.
   *
   * @param input 输入字符串
   * @return true是手机或者座机号码, false不是手机或者座机号码
   */
  public static boolean isPhoneOrTel(String input) {
    if (StringUtils.isBlank(input)) {
      return false;
    }
    return isPhoneNumber(input) || isTelephoneNumber(input);
  }
}
